home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
050
/
disk_425.arc
/
PLOT.LIB
< prev
next >
Wrap
Text File
|
1986-06-20
|
3KB
|
147 lines
procedure plot( { with arrays }
x, { as independant variable }
y, { as dependant variable }
ycalc { as fitted curve }
: ary;
{ and } m : integer { number of points });
{ plot y and ycalc as a function of x for m points }
{ if m is negative, only x and y are plotted }
const blank = ' ';
linel = 51;
var
ylabel : array[1..6] of real;
out : array[1..linel] of char;
lines,i,j,jp,l,n: integer;
iskip,yonly : boolean;
xlow,xhigh,xnext,xlabel,xscale,signxs,
ymin,ymax,change,yscale,ys10 : real;
function pscale(p: real): integer;
begin
pscale:=trunc((p-ymin)/yscale+1)
end; { pscale}
procedure outlin(xname: real);
{ output a line }
var i,max : integer;
begin
write(xname:8:2,blank); { line label }
max:=linel+1;
repeat { skip blanks on end of line }
max:=max-1
until (out[max]<>blank) or (max=1);
for i:=1 to max do
write(out[i]);
writeln;
for i:=1 to max do
out[i]:=blank { blank next line }
end; { outlin}
procedure setup(index: integer);
{ setup the plus and asterisk for printing }
const star = '*';
plus = '+';
var i : integer;
begin
i:=pscale(y[index]);
out[i]:=plus;
if not yonly then
begin { add ycalc too }
i:=pscale(ycalc[index]);
out[i]:=star
end
end; { setup }
begin { body of plot }
if m>0 then { plot y and ycalc vs x }
begin
n:=m;
yonly:=false
end
else { plot only y vs x }
begin
n:=-m;
yonly:=true
end;
{ space out alternate lines }
lines:=2*(n-1)+1;
writeln;
xlow:=x[1];
xhigh:=x[n];
ymax:=y[1];
ymin:=ymax;
xscale:=(xhigh-xlow)/(lines-1);
signxs:=1.0;
if xscale<0.0 then signxs:=-1.0;
for i:=1 to n do
begin
if y[i]<ymin then ymin:=y[i];
if y[i]>ymax then ymax:=y[i];
if not yonly then
begin
if ycalc[i]<ymin then ymin:=ycalc[i];
if ycalc[i]>ymax then ymax:=ycalc[i]
end { if yonly }
end;
yscale:=(ymax-ymin)/(linel-1);
ys10:=yscale*10;
ylabel[1]:=ymin; { y axis }
for i:=1 to 4 do
ylabel[i+1]:=ylabel[i]+ys10;
ylabel[6]:=ymax;
for i:=1 to linel do
out[i]:=blank; { blank line }
setup(1);
l:=1;
xlabel:=xlow;
iskip:=false;
for i:=2 to lines do { set up a line }
begin
xnext:=xlow+xscale*(i-1);
if iskip then writeln(' -')
else
begin
l:=l+1;
while
(x[l]-(xnext-0.5*xscale))*signxs<=0.0 do
begin
setup(l); { setup print line }
l:=l+1
end; { while }
outlin(xlabel); { print a line }
for j:=1 to linel do
out[j]:=blank { blank line }
end; { if skip }
if (x[l]-(xnext+0.5*xscale))*signxs>0.0 then iskip:=true
else
begin
iskip:=false;
xlabel:=xnext;
setup(l) { setup print line }
end
end; { for-loop }
outlin(xhigh); { last line }
write(' ');
for i:=1 to 6 do
write(' ^ ');
writeln;
write(' ');
for i:=1 to 6 do
write(ylabel[i]:9:1,blank);
writeln;
writeln
end; { PLOT }